package com.ruoyi.web.controller.common;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.ComArea;
import com.ruoyi.system.service.ComAreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 地区管理Controller
 *
 * @author tianl
 * @date 2024-12-19
 */
@RestController
@RequestMapping("/com/comArea" )
public class ComAreaController extends BaseController {
    @Autowired
    private ComAreaService comAreaService;

    /**
     * 查询地区管理列表
     */
    @GetMapping("/list" )
    public AjaxResult list(ComArea comArea) {
        List<ComArea> list = comAreaService.list(comArea);
        return success(list);
    }

    /**
     * 导出地区管理列表
     */
    @Log(title = "地区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ComArea comArea) {
        List<ComArea> list = comAreaService.list(comArea);
        ExcelUtil<ComArea> util = new ExcelUtil<ComArea>(ComArea.class);
        util.exportExcel(response, list, "地区管理数据" );
    }

    /**
     * 获取地区管理详细信息
     */
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return success(comAreaService.selectById(id));
    }

    /**
     * 新增地区管理
     */
    @Log(title = "地区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ComArea comArea) {
        comAreaService.beforeSave(comArea);
        return AjaxResult.success();
    }

    /**
     * 修改地区管理
     */
    @Log(title = "地区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ComArea comArea) {
        comAreaService.beforeSave(comArea);
        return AjaxResult.success();
    }

    /**
     * 删除地区管理
     */
    @Log(title = "地区管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(comAreaService.deleteByIds(ids));
    }
}
